<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <?php
        include_once ('../includes/utilidades.php');
        session_start();

        //print_r($_REQUEST);
        //print "____>" . strlen($_REQUEST['login']);  
                
        $idusuario=$_REQUEST['id'];
           
        if ( (isset($_REQUEST['op'])) && ($_REQUEST['op']=='delRol') ) {
            delRol($idusuario,$_REQUEST['rol']);
        }
        
        if ( (isset($_REQUEST['op'])) && ($_REQUEST['op']=='addRol') &&(strlen($_REQUEST['rolName'])>0) ) {
            addRol($idusuario,$_REQUEST['rolName']);
        }
        
        
        $sql = "select * from usuario usu,rol_usuario rol where rol.idusuario=usu.id and usu.id=" . $idusuario . " order by idusuario";
        $us = select2($sql);
        print "<table>";
        print "<tr><th>Login:</th><td>" . $us[0]['login'] . "</td></tr>" .
                "<tr><th>Nombre:</th><td>" . $us[0]['nombre'] . "</td></tr>" .
                "<tr><th>Apellidos:</th><td>" . $us[0]['apellidos'] . "</td></tr>" .
                "<tr><th>email:</th><td>" . $us[0]['email'] . "</td></tr>";
  /*      
        print "<tr><td>". $us[0]['login'] . "</td>" .
                "<td>". $us[0]['nombre'] ."</td>" .
                "<td>". $us[0]['apellidos'] ."</td>" .
                "<td>". $us[0]['email'] ."</td>" .
                "</tr>";
*/
        print "</table>";
        
        print "<table border=1>";
        print "<tr><th>Roles</th></tr>";
        foreach ($us as $rol) {
            print "<tr>" .
                    "<td>" . $rol['rol'] . "</td>" . 
                    "<td>" . "<a href=editarUsuario.php?id=" . $idusuario . "&op=delRol&rol=" . $rol['rol'] . ">Quitar rol</a></td>" . 
                    //"<td> LLARA BOBA </td>" . 
                    "</tr>";
        }
        print "</table>";

        
        //print "<h3>Añadir rol</h3>";
        print "<form name=nuevoRol method=post action=editarUsuario.php>";        
        print "<table>";
        print "<tr><td>Nuevo Rol</td><td><input type=text name='rolName' value=''></td></tr>";
        print "<input type=hidden name=op value='addRol'>";
        print "<input type=hidden name=id value='" . $idusuario . "'>";
        print "<tr><td></td><td><input type=submit value='Añadir Rol'></td></tr>";
        print "</table>";
        print "</form>";
        
        //print_r($_SESSION);
        //$actual = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['SERVER_NAME'] . "/atletismo/index.php";
        //header("location: " . $actual); // Redirecting To Other Page
        ?>
    </body>
</html>
